package com.ruoyi.app.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.app.domain.AppTeamType;
import com.ruoyi.app.domain.bo.AppTeamTypeBo;
import com.ruoyi.app.domain.vo.AppTeamTotalTypeVo;
import com.ruoyi.app.domain.vo.AppTeamTypeVo;
import com.ruoyi.app.mapper.AppTeamTypeMapper;
import com.ruoyi.app.service.IAppTeamTypeService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * APP拼团类型Service业务层处理
 *
 * @author heike
 * @date 2023-08-16
 */
@RequiredArgsConstructor
@Service
public class AppTeamTypeServiceImpl implements IAppTeamTypeService {

    private final AppTeamTypeMapper baseMapper;

    /**
     * 查询APP拼团类型
     */
    @Override
    public AppTeamTypeVo queryById(Long id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询APP拼团类型列表
     */
    @Override
    public TableDataInfo<AppTeamTypeVo> queryPageList(AppTeamTypeBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<AppTeamType> lqw = buildQueryWrapper(bo);
        Page<AppTeamTypeVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询APP拼团类型列表
     */
    @Override
    public List<AppTeamTypeVo> queryList(AppTeamTypeBo bo) {
        LambdaQueryWrapper<AppTeamType> lqw = buildQueryWrapper(bo);
        lqw.orderByDesc(AppTeamType::getSort);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<AppTeamType> buildQueryWrapper(AppTeamTypeBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<AppTeamType> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(bo.getName()), AppTeamType::getName, bo.getName());
        lqw.eq(bo.getType() != null, AppTeamType::getType, bo.getType());
        lqw.eq(StringUtils.isNotBlank(bo.getStatus()), AppTeamType::getStatus, bo.getStatus());
        return lqw;
    }

    /**
     * 新增APP拼团类型
     */
    @Override
    public Boolean insertByBo(AppTeamTypeBo bo) {
        AppTeamType add = BeanUtil.toBean(bo, AppTeamType.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改APP拼团类型
     */
    @Override
    public Boolean updateByBo(AppTeamTypeBo bo) {
        AppTeamType update = BeanUtil.toBean(bo, AppTeamType.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(AppTeamType entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除APP拼团类型
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public ArrayList<AppTeamTotalTypeVo> typeList() {
        ArrayList<AppTeamTotalTypeVo> list = new ArrayList<>();
        AppTeamTotalTypeVo one = new AppTeamTotalTypeVo();
        one.setId(1L);
        one.setName("约饭");
        one.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/1d77ae3c63544cde8ad1343bc1a14ae5.png");
        one.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/1d77ae3c63544cde8ad1343bc1a14ae5.png");
        one.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/77ceeaf3900f459d8b3b11628b813f00.png");
        list.add(one);

        AppTeamTotalTypeVo two = new AppTeamTotalTypeVo();
        two.setId(2L);
        two.setName("运动户外");
        two.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/a26d3e356b774be3b68de39abe0a7d03.png");
        two.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/a26d3e356b774be3b68de39abe0a7d03.png");
        two.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/28/5917c8795a7e4afbb046a0f73e27e8bf.png");
        list.add(two);

        AppTeamTotalTypeVo three = new AppTeamTotalTypeVo();
        three.setId(3L);
        three.setName("酒吧KTV");
        three.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/1c253cdcfe7146a1bef8d6528754e999.png");
        three.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/1c253cdcfe7146a1bef8d6528754e999.png");
        three.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/03eee2c34d854924a7abb9db9f1717bd.png");
        list.add(three);

        AppTeamTotalTypeVo four = new AppTeamTotalTypeVo();
        four.setId(4L);
        four.setName("演出");
        four.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/4d5c1a9152e34763ba5f5b3c7b007916.png");
        four.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/4d5c1a9152e34763ba5f5b3c7b007916.png");
        four.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/a16a77160bdc46d9b00f2f9c9a24054c.png");
        list.add(four);

        AppTeamTotalTypeVo five = new AppTeamTotalTypeVo();
        five.setId(5L);
        five.setName("旅行");
        five.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/2b44ae83eb274f2689c341fb1b21511a.png");
        five.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/2b44ae83eb274f2689c341fb1b21511a.png");
        five.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/7eb7831c37364c7b99741bb0f8b129b3.png");
        list.add(five);

        AppTeamTotalTypeVo six = new AppTeamTotalTypeVo();
        six.setId(6L);
        six.setName("密室剧本");
        six.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/79dcc4f4ab4e4a5ca97ef574af2dea50.png");
        six.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/79dcc4f4ab4e4a5ca97ef574af2dea50.png");
        six.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/7ff2058f437a4f6ba2a7ffa22497d7e4.png");
        list.add(six);

        AppTeamTotalTypeVo eight = new AppTeamTotalTypeVo();
        eight.setId(8L);
        eight.setName("游玩");
        eight.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/7ee8d9cc29b34cdbb8369d4bf70f9187.png");
        eight.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/7ee8d9cc29b34cdbb8369d4bf70f9187.png");
        eight.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/47cabd46404148bdb79f8b334e9b35a6.png");
        list.add(eight);

        AppTeamTotalTypeVo nine = new AppTeamTotalTypeVo();
        nine.setId(9L);
        nine.setName("学习");
        nine.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/33e982f5ceaf480ba39e477c4579c513.png");
        nine.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/33e982f5ceaf480ba39e477c4579c513.png");
        nine.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/9e043bca86fd41eea33130da74af4e73.png");
        list.add(nine);

        AppTeamTotalTypeVo ten = new AppTeamTotalTypeVo();
        ten.setId(10L);
        ten.setName("聊天游戏");
        ten.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/b7bbaaa2f170485796f1e2c90ecfaa0d.png");
        ten.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/b7bbaaa2f170485796f1e2c90ecfaa0d.png");
        ten.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/ddb34917be444e3cbd204b9cc6861b80.png");
        list.add(ten);
        return list;
    }

    /**
     * 根据ID获取对应的分类详情
     *
     * @param id ID
     * @return
     */
    public AppTeamTotalTypeVo getInfo(Long id) {
        HashMap<Long, AppTeamTotalTypeVo> hashMap = new HashMap<>();
        AppTeamTotalTypeVo one = new AppTeamTotalTypeVo();
        one.setId(1L);
        one.setName("约饭");
        one.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/1d77ae3c63544cde8ad1343bc1a14ae5.png");
        one.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/1d77ae3c63544cde8ad1343bc1a14ae5.png");
        one.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/77ceeaf3900f459d8b3b11628b813f00.png");
        hashMap.put(1L, one);

        AppTeamTotalTypeVo two = new AppTeamTotalTypeVo();
        two.setId(2L);
        two.setName("运动户外");
        two.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/a26d3e356b774be3b68de39abe0a7d03.png");
        two.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/a26d3e356b774be3b68de39abe0a7d03.png");
        two.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/8a95a93aabb84173949f9720a015132f.png");
        hashMap.put(2L, two);

        AppTeamTotalTypeVo three = new AppTeamTotalTypeVo();
        three.setId(3L);
        three.setName("酒吧KTV");
        three.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/1c253cdcfe7146a1bef8d6528754e999.png");
        three.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/1c253cdcfe7146a1bef8d6528754e999.png");
        three.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/03eee2c34d854924a7abb9db9f1717bd.png");
        hashMap.put(3L, three);

        AppTeamTotalTypeVo four = new AppTeamTotalTypeVo();
        four.setId(4L);
        four.setName("演出");
        four.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/4d5c1a9152e34763ba5f5b3c7b007916.png");
        four.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/4d5c1a9152e34763ba5f5b3c7b007916.png");
        four.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/a16a77160bdc46d9b00f2f9c9a24054c.png");
        hashMap.put(4L, four);

        AppTeamTotalTypeVo five = new AppTeamTotalTypeVo();
        five.setId(5L);
        five.setName("旅行");
        five.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/2b44ae83eb274f2689c341fb1b21511a.png");
        five.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/2b44ae83eb274f2689c341fb1b21511a.png");
        five.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/7eb7831c37364c7b99741bb0f8b129b3.png");
        hashMap.put(5L, five);

        AppTeamTotalTypeVo six = new AppTeamTotalTypeVo();
        six.setId(6L);
        six.setName("密室剧本");
        six.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/79dcc4f4ab4e4a5ca97ef574af2dea50.png");
        six.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/79dcc4f4ab4e4a5ca97ef574af2dea50.png");
        six.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/7ff2058f437a4f6ba2a7ffa22497d7e4.png");
        hashMap.put(6L, six);

        AppTeamTotalTypeVo eight = new AppTeamTotalTypeVo();
        eight.setId(8L);
        eight.setName("游玩");
        eight.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/7ee8d9cc29b34cdbb8369d4bf70f9187.png");
        eight.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/7ee8d9cc29b34cdbb8369d4bf70f9187.png");
        eight.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/47cabd46404148bdb79f8b334e9b35a6.png");
        hashMap.put(8L, eight);

        AppTeamTotalTypeVo nine = new AppTeamTotalTypeVo();
        nine.setId(9L);
        nine.setName("学习");
        nine.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/33e982f5ceaf480ba39e477c4579c513.png");
        nine.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/33e982f5ceaf480ba39e477c4579c513.png");
        nine.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/9e043bca86fd41eea33130da74af4e73.png");
        hashMap.put(9L, nine);

        AppTeamTotalTypeVo ten = new AppTeamTotalTypeVo();
        ten.setId(10L);
        ten.setName("聊天游戏");
        ten.setImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/b7bbaaa2f170485796f1e2c90ecfaa0d.png");
        ten.setModeImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/b7bbaaa2f170485796f1e2c90ecfaa0d.png");
        ten.setMapImage("http://heike-chat.oss-cn-shanghai.aliyuncs.com/2023/08/24/ddb34917be444e3cbd204b9cc6861b80.png");
        hashMap.put(10L, ten);
        return hashMap.get(id);
    }

    @Override
    public String costName(String type) {
        HashMap<String, String> map = new HashMap<>();
        map.put("0", "AA");
        map.put("1", "你请客");
        map.put("2", "我请客");
        map.put("3", "免费");
        return map.get(type);
    }


}
